#include <bits/stdc++.h>
using namespace std;
long long T, n, m, l, V, ans1, ans2;
int d[100005], v[100005], a[100005], p[100005];
int tot[100005];
bool ch[10003][10003];
inline int read()
{
    char c = getchar();
    bool flag = 0;
    int x = 0;
    if(c == '-')
    {
        flag = 1;
        c = getchar();
    }
    while(c>='0' && c<='9')
    {
        x = (x<<3) + (x<<1) + c-'0';
        c = getchar();
    }
    if(flag) x = -x;
    return x;
}
void check(int x)
{
    double ll = d[x] + max((double)0, (double)(1ll*V*V-1ll*v[x]*v[x])/2/a[x]);
    double rl = d[x] + min((double)l-d[x]+1, (double)(1ll*V*V-1ll*v[x]*v[x])/2/a[x]);
    if(a[x]<0) ll = -1;
    if(a[x]>0) rl = l+1;
    long long lll = 1ll*ll*10000000;
    long long rrr = 1ll*rl*10000000;
    lll = round(lll/10000000.0);
    rrr = round(rrr/10000000.0);
    for(int y = 1; y <= m; ++y)
    {
        if(d[x] > p[y])
            ch[x][y] = 0;
        else if(v[x]<=V && a[x]<=0)
            ch[x][y] = 0;
        else if(v[x]>V && a[x]>=0)
            ch[x][y] = 1;
        else if(lll<p[y] && p[y]<rrr)
            ch[x][y] = 1;
        else
            ch[x][y] = 0;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    T = read();
    register int i, j;
    while(T--)
    {
        memset(tot, 0, sizeof(tot));
        ans1 = 0; ans2 = 0;
        n = read(); m = read(); l = read(); V = read();
        for(i = 1; i <= n; ++i)
        {
            d[i] = read(); v[i] = read(); a[i] = read();
        }
        for(i = 1; i <= m; ++i)
            p[i] = read();
        for(i = 1; i <= n; ++i)
        {
            check(i);
            for(j = 1; j <= m; ++j)
                if(ch[i][j]) ++tot[i];
        }
            
        for(i = 1; i <= n; ++i)
            if(tot[i])
                ++ans1;
        for(j = 1; j <= m; ++j)
        {
            bool flag = 1;
            for(i = 1; i <= n; ++i)
            {
                if(ch[i][j] && tot[i]==1)
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                ++ans2;
                for(i = 1; i <= n; ++i)
                    if(ch[i][j])
                        --tot[i];
            }
        }
        /*cout << "!! " << endl;
        for(int i = 1; i <= n; ++i)
        {
            for(int j = 1; j <= m; ++j)
                cout << ch[i][j] << ' ';
            cout << endl;
        }*/
        cout << ans1 << ' ' << ans2 << endl;
    }
}